<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Encrypt a CMS message</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.openssl-cms-decrypt.html">« openssl_cms_decrypt</a></li>
      <li style="float: right;"><a href="function.openssl-cms-read.html">openssl_cms_read »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.openssl.html">OpenSSL 函数</a></li>
    <li>Encrypt a CMS message</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.openssl-cms-encrypt" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">openssl_cms_encrypt</h1>
  <p class="verinfo">(PHP 8)</p><p class="refpurpose"><span class="refname">openssl_cms_encrypt</span> &mdash; <span class="dc-title">Encrypt a CMS message</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.openssl-cms-encrypt-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>openssl_cms_encrypt</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$input_filename</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$output_filename</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="class.opensslcertificate.html" class="type OpenSSLCertificate">OpenSSLCertificate</a></span>|<span class="type">array</span>|<span class="type">string</span></span> <code class="parameter">$certificate</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">?</span><span class="type"><span class="type">array</span><span class="type"></span></span> <code class="parameter">$headers</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$flags</code><span class="initializer"> = 0</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$encoding</code><span class="initializer"> = <strong><code>OPENSSL_ENCODING_SMIME</code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$cipher_algo</code><span class="initializer"> = <strong><code>OPENSSL_CIPHER_AES_128_CBC</code></strong></span></span><br>): <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   This function encrypts content to one or more recipients,
   based on the certificates that are passed to it.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.openssl-cms-encrypt-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt>
<code class="parameter">input_filename</code></dt>

    <dd>

     <p class="para">
       The file to be encrypted.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">output_filename</code></dt>

    <dd>

     <p class="para">
      The output file.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">certificate</code></dt>

    <dd>

     <p class="para">
      Recipients to encrypt to.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">headers</code></dt>

    <dd>

     <p class="para">
      Headers to include when S/MIME is used.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">flags</code></dt>

    <dd>

     <p class="para">
      Flags to be passed to CMS_sign.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">encoding</code></dt>

    <dd>

     <p class="para">
      An encoding to output. One of <strong><code>OPENSSL_ENCODING_SMIME</code></strong>,
      <strong><code>OPENSSL_ENCODING_DER</code></strong> or <strong><code>OPENSSL_ENCODING_PEM</code></strong>.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">cipher_algo</code></dt>

    <dd>

     <p class="para">
      A cypher to use.
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.openssl-cms-encrypt-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>true</code></strong>， 或者在失败时返回 <strong><code>false</code></strong>。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.openssl-cms-encrypt-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.1.0</td>
      <td>
       The default cipher algorithm (<code class="parameter">cipher_algo</code>) is now
       AES-128-CBC (<strong><code>OPENSSL_CIPHER_AES_128_CBC</code></strong>). Previously,
       PKCS7/CMS was used (<strong><code>OPENSSL_CIPHER_RC2_40</code></strong>).
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


</div></div></div></body></html>